package cj.web.yc.controllers;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.yc.constants.PayHistoryTypeEnum;
import cj.web.yc.domain.PayHistory;
import cj.web.yc.service.PayHistoryService;

@Path("/payHistory")
public class PayHistoryController{

	private static Logger logger = Logger.getLogger(PayHistoryController.class.getName());
	
	@Autowired
	private PayHistoryService payHistoryService;
	
	@Get("show")
	public String show(Model model) {
		model.add("payHistoryTypeEnum",EnumSet.allOf(PayHistoryTypeEnum.class));
		return "/views/yc/payHistoryList.vm";
	}

	@Post("getList")
	public String queryList(PayHistory payHistory) {
	
		//当前页  
		payHistory.setStart((payHistory.getPage()-1)*payHistory.getRows());
		payHistory.setLength(payHistory.getRows());
		
		JSONObject jo = new JSONObject();
		
		Map rep = payHistoryService.query(payHistory);
		List<PayHistory> objs = (List<PayHistory>) rep.get("payHistorylis");
		for(PayHistory obj:objs){
			obj.setTypeName(PayHistoryTypeEnum.getName(obj.getType()));
		}
		int size = (int) rep.get("size");
		
		jo.put("rows", objs);
		jo.put("total", size);
		return "@"+jo.toString();
	}
}
